//
//  TopBarView.m
//  InTheSnow
//
//  Created by di on 7/30/09.
//  Copyright 2009 INTELLECTSOFT. All rights reserved.
//
#import "DescrViewController.h"
#import "ToMailController.h"
#import "TopBarView.h"


@implementation TopBarView
 
@synthesize toBack;
@synthesize toShare;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
		UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
		[backBtn setFrame:CGRectMake(10, 10, 53, 24)];
		[backBtn setBackgroundImage:[UIImage imageNamed:@"back_off.png"] forState:UIControlStateNormal];	
		[backBtn addTarget:self action:@selector(toBackController) forControlEvents:UIControlEventTouchUpInside];
		[backBtn setHidden:YES];
		[self addSubview:backBtn]; 
		[self setToBack:backBtn];
		
		self.clipsToBounds = YES;
		
		
		UIButton *toShare_ = [UIButton buttonWithType:UIButtonTypeCustom];
		[toShare_ setFrame:CGRectMake(250, 6, 59, 32)];
		[toShare_ setBackgroundImage:[UIImage imageNamed:@"share_off.png"] forState:UIControlStateNormal];
		[toShare_ addTarget:self action:@selector(toShareLink) forControlEvents:UIControlEventTouchUpInside];
		[toShare_ setHidden:YES];
		[self addSubview:toShare_];
		[self setToShare:toShare_];
		
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    [[UIImage imageNamed:@"header.png"] drawInRect:rect];
}

- (void)toBackController{
	[[NSNotificationCenter defaultCenter] postNotificationName:@"Back" object:nil];
}

- (void)toShareLink{ 
	UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle: @"Share" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil  otherButtonTitles:@"To e-mail", nil];
//    [sheet showInView:self.superview];
	[sheet showInView:[[__delegate tabBarController] view]];
    [sheet release];
}

 
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
	NSLog([[[[__delegate tabBarController] moreNavigationController]visibleViewController]description]);
	if(buttonIndex == 1) return;
			News *new =[(DescrViewController*)[(UINavigationController*)[[__delegate tabBarController] selectedViewController] visibleViewController] currentNew];
	ToMailController *tmp = [[ToMailController alloc] initWithNibName:@"ToMailController" bundle:[NSBundle mainBundle] news:new];
	[[__delegate navigationController] pushViewController:tmp animated:YES];
	[tmp release];
}


- (void)dealloc {
	
	[toBack release];
	[toShare release];
    [super dealloc];
}


@end
